import requests
import json
from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad # 去填充
import base64

headers = {
    "Accept": "application/json, text/plain, */*",
    "Accept-Language": "zh-CN,zh;q=0.9",
    "Cache-Control": "no-cache",
    "Connection": "keep-alive",
    "Content-Type": "application/json;charset=UTF-8",
    "Origin": "https://www.swguancha.com",
    "Pragma": "no-cache",
    "Referer": "https://www.swguancha.com/",
    "Sec-Fetch-Dest": "empty",
    "Sec-Fetch-Mode": "cors",
    "Sec-Fetch-Site": "same-site",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36",
    "deviceType": "1",
    "sec-ch-ua": "\"Google Chrome\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\""
}
url = "https://app.swguancha.com/client/v1/cPublic/consumer/baseInfo"
data = {
    "size": 6,
    "current": 1,
    "propertyCode": [
        "DISTRICT_PROP_GJ025_RJDQSCZZ",
        "DISTRICT_PROP_GJ117_NMSYGGQDCYYCLS",
        "DISTRICT_PROP_GJ001_NMHJRK"
    ],
    "dimensionTime": "2019",
    "levelType": 2
}
data = json.dumps(data, separators=(',', ':'))
response = requests.post(url, headers=headers, data=data)

print(response.text) # base64



""" 
    AES加密 密钥:l.encoding('utf-8') => l = "QV1f3nHn2qm7i3xrj3Y9K9imDdGTjTu9"
  
  模式:ECB  padding:Pkcs7
 var n = u.enc.Utf8.parse(l)
                      , r = u.AES.decrypt(t.data, n, {
                        mode: u.mode.ECB,
                        padding: u.pad.Pkcs7
                    })
                      , i = r.toString(u.enc.Utf8)
                      , s = JSON.parse(i);
                    t.data = s
"""

aes = AES.new(key='QV1f3nHn2qm7i3xrj3Y9K9imDdGTjTu9'.encode('utf-8'),
              mode=AES.MODE_ECB)
d = aes.decrypt(base64.b64decode(response.text))
d = unpad(d,16)
data = d.decode('utf-8')

print(data)




















